/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bean.session;

import entity.BatchEntity;
import entity.DataObjectEntity;
import entity.LocationQuantityEntity;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.Stateless;
import javax.faces.model.DataModel;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

/**
 *
 * @author wei
 */
@Stateless
public class BatchEntityFacade extends AbstractFacade<BatchEntity> {

    @PersistenceContext(unitName = "MacTeam-warPU")
    private EntityManager em;

    protected EntityManager getEntityManager() {
        return em;
    }

    public BatchEntityFacade() {
        super(BatchEntity.class);
    }

    public List findAllCGBatches() {

        CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
        javax.persistence.criteria.CriteriaQuery cq = builder.createQuery();
        Root<DataObjectEntity> batchRoot = cq.from(BatchEntity.class);

        Predicate predicate1 = builder.equal(batchRoot.get("type"), "CG");

        cq.select(batchRoot);
        cq.where(builder.and(predicate1));
        return new ArrayList(getEntityManager().createQuery(cq).getResultList());
    }
    
        public List findAllRMBatches() {

        CriteriaBuilder builder = getEntityManager().getCriteriaBuilder();
        javax.persistence.criteria.CriteriaQuery cq = builder.createQuery();
        Root<DataObjectEntity> batchRoot = cq.from(BatchEntity.class);

        Predicate predicate1 = builder.equal(batchRoot.get("type"), "RM");

        cq.select(batchRoot);
        cq.where(builder.and(predicate1));
        return new ArrayList(getEntityManager().createQuery(cq).getResultList());
    }
}
